<template>
  <a-card :bordered="false">
    <v-table
      :columns="columns"
      :data="loadData"
      :showPagination="false"
      ref="table"
    >
      <template v-slot:buttons>
        <a-button type="primary" icon="plus" @click="$refs.deptAddOrUpdate.init('','add')" v-action="'sys:dept:save'">新建</a-button>
      </template>
      <span slot="action" slot-scope="{ row }">
         <a @click="edit(row)">修改</a>
        <a-divider type="vertical" />
        <a-popconfirm title="是否删除部门" @confirm="deletedom(row)" okText="是" cancelText="否">
          <a-icon slot="icon" type="question-circle-o" style="color: red" />
          <a href="javascript:;" style="color: red">删除</a>
        </a-popconfirm>
        <a-divider type="vertical" />
        <a href="javascript:;" @click="show(row)">查看</a>
      </span>
    </v-table>
    <dept-add-or-update
      ref="deptAddOrUpdate"
      @ok="handleOk"/>
  </a-card>
</template>

<script>
import { fetchList, delObj } from '@api/sys/dept'
import DeptAddOrUpdate from './deptAddOrUpdate'
import { TableMixin } from '@/mixins/TableMixin'
export default {
  name: 'Menu',
  mixins: [TableMixin],
  components: {
    DeptAddOrUpdate
  },
  data () {
    return {
      loading: false,
      columns: [
        {
          title: '部门名称',
          field: 'name',
          placeholder: '',
          search: false,
          treeNode: true
        },
        {
          title: '排序号',
          field: 'orderNum'
        },
        {
          title: '创建时间',
          field: 'createTime'
        },
        {
          title: '操作',
          width: '25%',
          field: 'action',
          slot: true
        }
      ],
      loadData: () => {
        return fetchList().then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.deptAddOrUpdate.init(record.id, 'edit')
    },
    deletedom (record) {
      delObj(record.deptId).then(_ => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    handleOk () {
      this.queryPage()
    },
    show (record) {
      this.$refs.deptAddOrUpdate.init(record.id, 'show')
    }
  },
  created () {
  }
}
</script>

<style scoped>

</style>
